function [ distance ] = getTransitionVectorDistance( profileA, profileB )
%Find the distance between copy number transition profiles for cells a and
%b, to be used to create a new phylogenetic tree
    
    %search for all transitions along profile A within some window near the
    %same site in profile B. If the transition doesn't exist within the
    %window, incremement the difference between the cells 
    
    %The advantage of this is that single copy number change events aren't
    %magnified too much 
   
    %ex: 223333322 22222222 have a pairwise edit distance of 5 but only
    %have a difference of 2 in terms of their copy # transitions. (2->3/nothing and
    %3->2/nothing)
    
    window = 3;
    distanceA = 0;
    distanceB = 0;

    for site=1:length(profileA)
        %if there is a change (ie the transition code is nonzero)
        if profileA(site)~=0
            transitionCode = profileA(site);
            if foundTransition(transitionCode,profileB,window,site) ~= 1
                distanceA = distanceA + 1;
                fprintf('foundA at %d\n', site);
            end
        end
    end
    
    for site=1:length(profileB)
        %if there is a change (ie the transition code is nonzero)
        if profileB(site)~=0
            transitionCode = profileB(site);
            if foundTransition(transitionCode,profileA,window,site) ~= 1
                distanceB = distanceB + 1;
                fprintf('foundB at %d\n', site);
            end
        end
    end
%     fprintf('distA: %d\ndistB:%d\n', distanceA, distanceB);
    
    distance = (distanceA + distanceB)/2;
end

function [ found ] = foundTransition(transitionCode, profileB, window, site)
    found = 0;
    
    from = max(1, site-window);
    to = min(size(profileB, 2), site+window);
%     fprintf('looking from %d to %d\n', from, to);
    for pos = from:to
        if profileB(pos) == transitionCode
            found = 1;
            return;
        end
    end
end
